# 管理端-公眾內容管理接口
from flask import Blueprint, request

from admin_route.public import addBackgroundImage, addNewNav, addPolicyFile, deleteBackgroundImage, deleteNavById, deletePolicyFile, getAllBackgroundImages, getBackgroundImage, getBottomInfo, getNavList, getPolicyFilesList, getPolicyFilesListPage, setBackgroundImageActiveStatus, updateBackgroundImage, updateBottomInfo, updateNavById, updatePolicyFileById

routes_public = Blueprint('routes_public', __name__)


@routes_public.route("/navManage/list", methods=['GET'])
def getNavAll():
    res = getNavList()
    return res


@routes_public.route("/navManage", methods=['POST'])
def addNav():
    data = request.get_json()
    res = addNewNav(data)
    return res


@routes_public.route("/navManage", methods=['PUT'])
def updateNav():
    data = request.get_json()
    id = data.get('id')
    res = updateNavById(id, data)
    return res


@routes_public.route("/navManage", methods=['DELETE'])
def deleteNav():
    id = request.args.get('id')
    res = deleteNavById(id)
    return res



@routes_public.route("/policyFiles/list", methods=['GET'])
def getPolicyFilesListAll():
    area = request.args.get('area')
    major1 = request.args.get('major1')
    major2 = request.args.get('major2')
    res = getPolicyFilesList(area, major1, major2)
    return res

@routes_public.route("/policyFiles/page", methods=['GET'])
def getPolicyFilesListPageFn():
    page = request.args.get('page', 1, type=int)
    per_page = request.args.get('perPage', 10, type=int)
    area = request.args.get('area')
    major1 = request.args.get('major1')
    major2 = request.args.get('major2')
    keyword = request.args.get('keyword')
    res = getPolicyFilesListPage(page, per_page, area, major1, major2, keyword)
    return res


@routes_public.route("/policyFiles", methods=['POST'])
def addPolicyFileFn():
    data = request.get_json()
    res = addPolicyFile(data)
    return res


@routes_public.route("/policyFiles", methods=['PUT'])
def updatePolicyFileByIdFn():
    data = request.get_json()
    id = data.get('id')
    res = updatePolicyFileById(id, data)
    return res

@routes_public.route("/policyFiles", methods=['DELETE'])
def deletePolicyFileFn():
    id = request.args.get('id')
    res = deletePolicyFile(id)
    return res


@routes_public.route("/bottomInfo", methods=['GET'])
def getBottomInfoById():
    id = request.args.get('id')
    res = getBottomInfo(id)
    return res


@routes_public.route("/bottomInfo", methods=['PUT'])
def updateBottomInfoById():
    data = request.get_json()
    id = data.get('id')
    res = updateBottomInfo(id, data)
    return res

@routes_public.route("/backgroundImage", methods=['GET'])
def getBackgroundImageInfo():
    res = getBackgroundImage()
    return res
@routes_public.route("/backgroundImage/setActive", methods=['PUT'])
def setBackgroundImageActive():
    data = request.get_json()
    id = data.get('id')
    is_active = data.get('isActive')
    res = setBackgroundImageActiveStatus(id, is_active)
    return res

@routes_public.route("/backgroundImages", methods=['GET'])
def getAllBackgroundImagesInfo():
    res = getAllBackgroundImages()
    return res

@routes_public.route("/backgroundImage", methods=['PUT'])
def updateBackgroundImageInfo():
    data = request.get_json()
    id = data.get('id')
    res = updateBackgroundImage(id, data)
    return res

@routes_public.route("/backgroundImage", methods=['DELETE'])
def deleteBackgroundImageInfo():
    id = request.args.get('id')
    res = deleteBackgroundImage(id)
    return res

@routes_public.route("/backgroundImage", methods=['POST'])
def addBackgroundImageInfo():
    data = request.get_json()
    res = addBackgroundImage(data)
    return res

